<?php
namespace Modules\Skinov\Controllers;

class IndexController extends ControllerBase {
  public function indexAction() {
    echo '首页';exit;
  }

  public function createMenuAction() {
    $app = $this -> easyWeChat;
    $easyWeChatConfig = $app -> getConfig();

    /**
     * 扫二维码码获取openid方式思路
     * 使用oauth2的跳转连接生成二维码，用微信扫跳转，获取openid
     */

    // 商城首页
    //$callbackShopUrl = urlencode($this -> config -> BASE_URL.'/skinov/callback/redirectFrontend?target_url=shop');
    $callbackShopUrl = urlencode('http://skinov.doias.com/index.php?s=/wap');
    // 用户中心
    //$callbackUserUrl = urlencode($this -> config -> BASE_URL.'/skinov/callback/redirectFrontend?target_url=user');
		$callbackUserUrl = urlencode('http://skinov.doias.com/index.php?s=/wap/member/index');
    $buttons = [
      [
        'type' => 'view',
        'name' => '商城首页',
        'url'  => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$easyWeChatConfig['app_id'].'&redirect_uri='.$callbackShopUrl.'&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'
      ], [
        'type' => 'view',
        'name' => '个人中心',
        'url'  => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$easyWeChatConfig['app_id'].'&redirect_uri='.$callbackUserUrl.'&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'
      ]
    ];
    var_dump($app->menu->create($buttons));exit;
    //var_dump($app->broadcasting->sendText('大家好！欢迎使用 测试。', ['oPEtEt_ioUWoBaWvMD6kixDeaGPM', 'oPEtEt_ioUWoBaWvMD6kixDeaGPM']));exit;
    $server -> push(function($message) {
      $text = new \EasyWeChat\Kernel\Messages\Text('您好！欢迎关注 text!');
      //$text -> setAttribute('to', 'gh_91e6a3334049');
      //$text -> setAttribute('from', 'oPEtEt_ioUWoBaWvMD6kixDeaGPM');
      return $text;
    });

    $server -> serve() -> send();exit;
  }
}
